package com.certification.service.impl;

import com.certification.entity.CertReject;
import com.certification.mapper.CertRejectMapper;
import com.certification.service.CertRejectService;
import com.certification.vo.ResponseMessage;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

/**
 * @author copa
 * @createDate 2022-03-29 16:36
 * @function
 */
@Service
public class CertRejectServiceImpl implements CertRejectService {

    @Resource
    private CertRejectMapper certRejectMapper;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public ResponseMessage<String> add(Integer certId, String remark) {
        CertReject certReject = new CertReject().setReason(remark)
                .setCertId(certId);
        int insert = certRejectMapper.insert(certReject);
        if (insert < 1) {
            return ResponseMessage.errorMsg("系统异常~请稍后再试~");
        }
        return ResponseMessage.success();
    }

    @Override
    public ResponseMessage<String> lastReject(Integer userId) {
        return ResponseMessage.success(certRejectMapper.selectLastReject(userId));
    }
}
